package com.greendeliver.activities;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.test.R;
import com.greendeliver.activities.base.BaseActivity;
import com.greendeliver.business.ServiceManager;

public class VoteServiceActivity extends BaseActivity {

	private String				ID_SERVICE;
	private String				APPLICATION_NAME;
	private float				APPLICATION_RATE;
	private float				USER_RATE;
	private int					APPLICATION_NBVOTE;

	private static final String	TAG_ID		= "ID_service";
	private static final String	TAG_NAME	= "name_service";
	private static final String	TAG_VOTE	= "vote_service";
	private static final String	TAG_NBVOTE	= "nb_vote_service";
	private TextView			textTitleEvent;
	private Button				bt1;

	private RatingBar			ratingbar1;

	@Override
	protected void onCreate( Bundle savedInstanceState ) {
		super.onCreate( savedInstanceState );
		setFullscreen();
		setContentView( R.layout.activity_vote_service );

		Intent i = getIntent();
		Log.d( "coucou", "1" );
		this.ID_SERVICE = i.getStringExtra( TAG_ID );
		Log.d( "coucou", "2" );
		this.APPLICATION_NAME = i.getStringExtra( TAG_NAME );
		Log.d( "coucou", "3" );
		this.APPLICATION_RATE = Float.parseFloat( i.getStringExtra( TAG_VOTE ) );
		Log.d( "coucou", "4" );
		this.APPLICATION_NBVOTE = Integer.parseInt( i.getStringExtra( TAG_NBVOTE ) );
		Log.d( "coucou", "5" );
		this.ratingbar1 = (RatingBar) findViewById( R.id.ratingBaruser );
		Log.d( "coucou", "6" );
		this.bt1 = (Button) findViewById( R.id.buttonvote );
		Log.d( "coucou", "7" );
		this.USER_RATE = 0;

		this.textTitleEvent = (TextView) findViewById( R.id.TitleService );
		textTitleEvent.setText( APPLICATION_NAME );

		// view products click event
		bt1.setOnClickListener( new View.OnClickListener()
		{
			@Override
			public void onClick( View view ) {
				USER_RATE = ratingbar1.getRating();
				ServiceManager sm = new ServiceManager();

				sm.rating_a_service( ID_SERVICE, USER_RATE, APPLICATION_RATE, APPLICATION_NBVOTE );

				// Serizable object
				sm.addSerializableVoteByEvent_BA( VoteServiceActivity.this, Integer.parseInt( ID_SERVICE ),
						APPLICATION_NAME );

				/*// Starting new intent
				Intent in = new Intent( getApplicationContext(),
						ServiceDetailActivity.class );
				// sending id to next activity
				in.putExtra( TAG_ID, ID_SERVICE );

				// starting new activity and expecting some response back
				startActivity( in );*/

				setResult( 0 );
				finish();
			}
		} );
	}

}
